package com.huawei.translate;

import org.apache.log4j.Logger;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

public class Main {
    public static void main(String[] args) {
        Logger log = Logger.getLogger(Main.class);
        try {
            Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
            scheduler.start();

            JobDetail job = JobBuilder.newJob(RefreshMsAccessTokenJob.class)
                    .withIdentity("RefreshMsAccessTokenJob", "translate")
                    .build();
            Trigger trigger = TriggerBuilder.newTrigger()
                    .withIdentity("RefreshMsAccessTokenJobTrigger", "translate")
                    .withSchedule(CronScheduleBuilder.cronSchedule("0 0/7 * * * ?"))
                    .startNow()
                    .build();

            JobDetail cleanupJob = JobBuilder.newJob(CleanupExpiredTokenJob.class)
                    .withIdentity("CleanupExpiredTokenJob", "translate")
                    .build();
            Trigger cleanupTrigger = TriggerBuilder.newTrigger()
                    .withIdentity("CleanupExpiredTokenJobTrigger", "translate")
                    .withSchedule(CronScheduleBuilder.cronSchedule("0 0 0 * * ?"))
                    .build();

            scheduler.scheduleJob(job, trigger);
            scheduler.scheduleJob(cleanupJob,cleanupTrigger);
        } catch (Exception e) {
            log.info(e.getMessage());
        }
    }
}
